package com.office.onlineInformation.sended.controller;


import com.office.onlineInformation.sended.pojo.OaOnlineMessage;
import com.office.onlineInformation.sended.service.SendedService;
import com.office.personalOffice.personalInfo.model.LoginUser;
import com.office.personalOffice.personalInfo.model.TbStaff;
import com.office.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 88168
 * @since 2022-10-25
 */
@RestController
@RequestMapping("/sended")
public class SendedController {
    @Autowired
    public SendedService service;

    /**
     * 删除已发送留言
     * @param informationId
     * @return
     */
    @RequestMapping("/delete/{informationId}")
    public String deleteMessage(@PathVariable int informationId){
        String message = service.deleteMessage(informationId);
        return message;
    }
    /**
     * 查询已发送留言
     * @return
     */
    @RequestMapping("/get")
    public PageModel<OaOnlineMessage> getList(OaOnlineMessage customManage, PageModel<OaOnlineMessage> pageModel,Authentication authentication){
        TbStaff user = getUser(authentication);
        customManage.setCreatedId(user.getId());
        System.out.println("**********"+customManage);
        PageModel<OaOnlineMessage> list = service.getList(customManage, pageModel);
        return pageModel;
    }
    /**
     * 根据id查询留言
     * @param Id
     * @return
     */
    @RequestMapping("/getOne/{Id}")
    public OaOnlineMessage getById(@PathVariable int Id){
       OaOnlineMessage message = service.getById(Id);
        return message;
    }

    public static TbStaff getUser(Authentication authentication){
        LoginUser principal =(LoginUser) authentication.getPrincipal();
        TbStaff user = principal.getUser();
        return user;
    }
}

